using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.ConnectionEngine.Adapters;
using Microsoft.ConnectionEngine.Common;

namespace Microsoft.ConnectionEngine.Registers.Core.ServiceProvider.NotificationServices
{
    public class ChangeNotificationAdapter : SystemAdapterBase
    {
        public ChangeNotificationAdapter():base()
        {
        }

        public ChangeNotificationAdapter(string hceserviceurl, string hceusername, string hcepasswoerd, string hsdserviceproviderid, string hsdencryptiontype,
                                         string hsdpublickey, string csaserviceproviderid, string csawebserviceurl, string csaencryptionalgorithm,
                                         string csapublickey, string csaprivatekey, string csaclientcertificate, string messagehandlerlist)
            : base(hceserviceurl, hceusername, hcepasswoerd, hsdserviceproviderid, hsdencryptiontype,
                   hsdpublickey, csaserviceproviderid, csawebserviceurl, csaencryptionalgorithm,
                   csapublickey, csaprivatekey, csaclientcertificate, messagehandlerlist)
        {
        }

        protected override System.Xml.XmlDocument AssembleMessage(object objMessage, int msgType)
        {
            /// I will assume that this Adapter will be part of the Service Provider Register, all the messges will be pre-assembled.
            /// So I will just make sure it is a string, load into XML and return the XML document.
            try
            {
                string payloadContent = (string)objMessage;
                System.Xml.XmlDocument payloadXml = new System.Xml.XmlDocument();
                payloadXml.LoadXml(payloadContent);
                return payloadXml;
            }
            catch (Exception ex)
            {
                SystemAdapterException sysEx = new SystemAdapterException(
                    SystemAdapterExceptionCause.Hl7PlayloadCreation,
                    "An error occurred assembling the Xml Message.",
                    ex);
                throw sysEx;
            }
        }
    }
}
